package com.example.springcloud.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.example.springcloud.domain.ScenicSpots;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.example.springcloud.domain.Route;
import com.example.springcloud.service.IRouteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 路线Controller
 * 
 * @author helian
 * @date 2025-03-01
 */
@RestController
@RequestMapping("/jiu-mount-huangshan/route")
@Api(tags = "路线管理")
public class RouteController extends BaseController
{
    @Autowired
    private IRouteService routeService;

    /**
     * 查询路线列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询路线列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "route", value = "查询路线列表", required = true, dataType = "Route")})
    @ApiResponses(@ApiResponse(code = 200, message = "查询景点信息列表成功", response = Route.class , responseContainer = "List"))
    public TableDataInfo list(Route route)
    {
        startPage();
        List<Route> list = routeService.selectRouteList(route);
        return getDataTable(list);
    }

    /**
     * 导出路线列表
     */
    @PreAuthorize("@ss.hasPermi('jiu-mount-huangshan:route:export')")
    @Log(title = "路线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Route route)
    {
        List<Route> list = routeService.selectRouteList(route);
        ExcelUtil<Route> util = new ExcelUtil<Route>(Route.class);
        util.exportExcel(response, list, "路线数据");
    }

    /**
     * 获取路线详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取路线详细信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "路线ID", required = true, dataType = "Long")})
    @ApiResponses(@ApiResponse(code = 200, message = "获取路线详细信息成功", response = Route.class))
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(routeService.selectRouteById(id));
    }

    /**
     * 新增路线
     */
    @PreAuthorize("@ss.hasPermi('jiu-mount-huangshan:route:add')")
    @Log(title = "路线", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Route route)
    {
        return toAjax(routeService.insertRoute(route));
    }

    /**
     * 修改路线
     */
    @PreAuthorize("@ss.hasPermi('jiu-mount-huangshan:route:edit')")
    @Log(title = "路线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Route route)
    {
        return toAjax(routeService.updateRoute(route));
    }

    /**
     * 删除路线
     */
    @PreAuthorize("@ss.hasPermi('jiu-mount-huangshan:route:remove')")
    @Log(title = "路线", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(routeService.deleteRouteByIds(ids));
    }
}
